package com.xigua.字符串;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/4/249:59
 */
public class _868_二进制间距 {

    public int binaryGap(int n) {
        String binary = Integer.toBinaryString(n);
        int length = binary.length();
        char[] chars = binary.toCharArray();
        int start = binary.indexOf("1");
        if (start == -1) return 0;
        int max = 0;
        for (int i = start+1; i < length; i++) {
            if (chars[i] == '1'){
                max = Math.max(i-start,max);
                start = i;
            }
        }
        return max;
    }

}
